<?php
include 'person.php';

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of student
 *
 * @author Aissa
 */
class student extends person{
    public $building_number;
    
    
    
public function reserve_room($room_number){
$query="select * from student where student_name='$this->name'";
$result=mysql_query($query)or die(mysql_error());
$row=mysql_fetch_array($result);
if($row['room_id']==0){
 $queryy="update student set room_id='$room_number' where student_name='$this->name'";
 $result1=mysql_query($queryy)or die(mysql_error()); 
 echo"تم التسجيل بنجاح";
 echo"<meta http-equiv='refresh'content='5'>";
}else{
 echo"لقد قمت بالتسجيل سابقا فى غرفة".$row['room_id'];
 echo"<meta http-equiv='refresh'content='5'>";
}    
    }
    public function show_all_rooms(){
        include_once 'room.php'; 
      $query=" select * from room where building_id='$this->building_number'";
      $result=mysql_query($query)or die(mysql_error());
      $counter=0;
     while($row=mysql_fetch_array($result)){
      $room=new room();
      $room->room_number=$row['room_id'];
      $room->capcity=$row['room_capacity'];
//      if($counter==0||$counter%3==0){
//          echo"
//     <div class='row'>              
//";
//      }
    echo"
   
    <table name='rooms' class='cell' >
    <tr><td><h7>غرفة $room->room_number</h7></td></tr>
";      
    $query1="select student_name from student where building_number='$this->building_number' and room_id='$room->room_number'";     
     $result1=mysql_query($query1)or die(mysql_error());
     for($i=0;$i<$room->capcity;$i++){
         $row1=mysql_fetch_array($result1);
         $student_name=$row1['student_name'];
         $buffer="";
         $mark="";
         if(strlen($student_name)>3){
             $buffer="readonly";
             $mark="*";
         }
     echo"
         <tr><td><input type='text'value='$mark$student_name'id='$room->room_number@$i' $buffer> </td>
         <td><input type='hidden'value='$room->room_number'id='$room->room_number@$i@room_number'> </td></tr>
";
         
         
     }
     
     echo "
<tr><td><input type='button'value='save'onclick='save($room->room_number)'></td></tr>
</table>
            
             ";
     }
//     $counter++;
//     if($counter%3==0){
//         echo"</div>";
//     }
        
    }
     public function add_recomendation($recomended_id,$recomender_id,$room_id) {
      $query="INSERT INTO recomendation(recomended_id,recomender_id,room_id)
              VALUES ('$recomended_id','$recomender_id','$room_id')";
       mysql_query($query) or die (mysql_error());
  }
  public function getroomnum($id){
              $sql="select * from student where student_personalnumber='$id'";
              $query=mysql_query($sql); 
              $row=mysql_fetch_array($query);
              return $row['room_id'];
  }
  public function showrecomendation($id){
              $sql="select * from recomendation where recomended_id='$id'";
              $query=mysql_query($sql)or die(mysql_error());  
              return $query;
  }
  public function updateroom($roomid,$national_number){
      $query="Update student set room_id='$roomid' where student_personalnumber='$national_number'";
         mysql_query($query)or die(mysql_error());  
          }
            public function rejectrecomendation($roomid,$national_number){
      $query="Delete FROM recomendation where recomended_id='$national_number'";
         mysql_query($query)or die(mysql_error());  
          }
   
   
}?>
